<?php
	session_start();
	$_SESSION['route'] = $_GET['route'];
	$_SESSION['xtime'] = $_GET['xtime'];
	$_SESSION['ytime'] = $_GET['ytime'];
	$_SESSION['type'] = $_GET['type'];
	$_SESSION['price'] = $_GET['price'];
	$link = mysql_connect("localhost", "root", "1234");
	mysql_select_db("busticket", $link);
	mysql_query("SET NAMES UTF8");
	$query = "select * from listbus where route='".$_GET['route']."' and xtime=".$_GET['xtime']." and ytime=".$_GET['ytime']."";
	$result = mysql_query($query,$link);
	if(mysql_num_rows($result) == 0){
		$query = "select * from busseat";
		$result = mysql_query($query,$link);
		$_SESSION['seat'] = array();
		while($object = mysql_fetch_object($result)){
			$_SESSION['seat'][] = $object->seatname;
		}
		mysql_close($link);
	} else {
		$busid = mysql_fetch_object($result);
		$_SESSION['busid'] = $busid->id;
		$query = "select * from busseat where busid = ".$busid->id."";
		$result = mysql_query($query,$link);
		$_SESSION['seat'] = array();
		while($object = mysql_fetch_object($result)){
			$_SESSION['seat'][] = $object->seatname;
		}
		mysql_close($link);
	}
	header("Location:../view/chooseseat.php");
?>